<?php
/**
 * Created by PhpStorm.
 * User: ouryun
 * Date: 2021/8/16
 * Time: 8:39
 */

namespace app\admin\controller;


use think\admin\Controller;
use think\App;

/**
 * 数据中心
 * Class DataCentre
 * @package app\admin\controller
 */
class DataCentre extends Controller
{
    /**
     * 人脸识别数据表
     * @var string
     */
    protected $table = 'lg_face_recognition';

    /**
     * 开始时间
     * @var string
     */
    public $start_time = ' 08:00';

    /**
     * 结束时间
     * @var string
     */
    public $end_time = ' 22:00';

    /**
     * 时间段
     * @var array
     */
    public $hours = [
        ['section' => '08:00', 'total' => 0],
        ['section' => '09:00', 'total' => 0],
        ['section' => '10:00', 'total' => 0],
        ['section' => '11:00', 'total' => 0],
        ['section' => '12:00', 'total' => 0],
        ['section' => '13:00', 'total' => 0],
        ['section' => '14:00', 'total' => 0],
        ['section' => '15:00', 'total' => 0],
        ['section' => '16:00', 'total' => 0],
        ['section' => '17:00', 'total' => 0],
        ['section' => '18:00', 'total' => 0],
        ['section' => '19:00', 'total' => 0],
        ['section' => '20:00', 'total' => 0],
        ['section' => '21:00', 'total' => 0],
        ['section' => '22:00', 'total' => 0],
    ];

    /**
     * 周期
     * @var array
     */
    public $period = [
        0 => [0, 1, 2, 3, 4, 5, 6],
        1 => [7, 8, 9, 10, 11, 12, 13, 14],
        2 => [15, 16, 17, 18, 19, 20, 21],
        3 => [22, 23, 24, 25, 26, 27, 28, 29]
    ];

    /**
     * 月周期
     * @var array
     */
    public $month_period = [
        0 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
        1 => [30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
        2 => [60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89]
    ];

    /**
     * 今日日期
     * @var false|string
     */
    public $today_date;

    /**
     * DataCentre constructor.
     * @param App $app
     */
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->today_date = date('Y-m-d', time());
    }

    /**
     * 渲染页面
     * @auth true
     * @login true
     */
    public function index()
    {
        $this->fetch('', [
            'title' => '数据中心'
        ]);
    }

    /**
     * 获取门店列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getShopList()
    {
        $list = $this->app->db->name('lg_distributor')->where('status', 1)->field('id,name')->select()->toArray();
        return returnJson(HTTP_CODE_SUCCESS, '成功', $list);
    }

    /**
     * 获取数据中心数据
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getCenterData()
    {
        $datas = $this->request->param();
        $vali = $this->app->validate->check($datas, [
            'contrast|对比' => 'require',
            'dimension|维度' => 'require'
        ]);
        if ($vali !== true) {
            return returnJson(HTTP_CODE_ERROR, $this->app->validate->getError(), '');
        }
        $contrast = $datas['contrast'];
        $dimension = $datas['dimension'];
        $shopId = $datas['shopId'] ?? 0;
        $title = [];
        //筛选门店
        $map = [];
        if ($shopId != 0) {
            $map['shop_id'] = $shopId;
        }
        //全门店数据展示
        if ($shopId == -1) {
            $data = $this->getAllShopFlow($datas, $contrast);
            return returnJson(HTTP_CODE_SUCCESS, '成功', $data);
        }
        switch ($dimension) {
            case 'today':
                //查询今天
                $nowStartTime = strtotime($this->today_date . $this->start_time);
                $nowEndTime = strtotime($this->today_date . $this->end_time);
                $todayList = $this->queryData($nowStartTime, $nowEndTime, "%H:00", $map, 0, 0);
                $list = $this->hours;
                foreach ($list as $key => $value) {
                    foreach ($todayList as $k => $v) {
                        if ($value['section'] == $v['section']) {
                            $list[$key]['total'] = $v['total'];
                        }
                    }
                }
                $abscissa = array_column($list, 'section');
                $nearLine = array_column($list, 'total');
                $title[0] = '今天';
                if ($contrast == 'hb') { //环比
                    //查询昨天
                    $yesterday = $this->_getDate('-1 day', $this->today_date);
                    $prevStartTime = strtotime($yesterday . $this->start_time);
                    $prevEndTime = strtotime($yesterday . $this->end_time);
                    $yesterdayList = $this->queryData($prevStartTime, $prevEndTime, "%H:00", $map, 0, 0);
                    $arr = $this->hours;
                    foreach ($arr as $key => $value) {
                        foreach ($yesterdayList as $k => $v) {
                            if ($value['section'] == $v['section']) {
                                $arr[$key]['total'] = $v['total'];
                            }
                        }
                    }
                    $farLine = array_column($arr, 'total');
                    $title[1] = '昨天';
                } else { //同比
                    //查询上个月今天
                    $prevStartTime = strtotime('-1 month', $nowEndTime);
                    $prevEndTime = strtotime('-1 month', $nowStartTime);
                    $prevList = $this->queryData($prevStartTime, $prevEndTime, '%H:00', $map, 0, 0);
                    $arr = $this->hours;
                    foreach ($arr as $key => $value) {
                        foreach ($prevList as $k => $v) {
                            if ($value['section'] == $v['section']) {
                                $arr[$key]['total'] = $v['total'];
                            }
                        }
                    }
                    $farLine = array_column($arr, 'total');
                    $title[1] = '上个月今天';
                }
                //性别分析
                $genderList = $this->queryGenderData($nowStartTime, $nowEndTime, $map);
                break;
            case 'yesterday':
                //查询昨天
                $nowStartTime = strtotime('-1 day', strtotime($this->today_date . $this->start_time));
                $nowEndTime = strtotime('-1 day', strtotime($this->today_date . $this->end_time));
                $todayList = $this->queryData($nowStartTime, $nowEndTime, "%H:00", $map, 0, 0);
                $list = $this->hours;
                foreach ($list as $key => $value) {
                    foreach ($todayList as $k => $v) {
                        if ($value['section'] == $v['section']) {
                            $list[$key]['total'] = $v['total'];
                        }
                    }
                }
                $abscissa = array_column($list, 'section');
                $nearLine = array_column($list, 'total');
                $title[0] = '昨天';
                if ($contrast == 'hb') { //环比
                    //查询前天
                    $yesterday = $this->_getDate('-2 day', $this->today_date);
                    $prevStartTime = strtotime($yesterday . $this->start_time);
                    $prevEndTime = strtotime($yesterday . $this->end_time);
                    $yesterdayList = $this->queryData($prevStartTime, $prevEndTime, "%H:00", $map, 0, 0);
                    $arr = $this->hours;
                    foreach ($arr as $key => $value) {
                        foreach ($yesterdayList as $k => $v) {
                            if ($value['section'] == $v['section']) {
                                $arr[$key]['total'] = $v['total'];
                            }
                        }
                    }
                    $farLine = array_column($arr, 'total');
                    $title[1] = '前天';
                } else { //同比
                    //上个月这天
                    $prevStartTime = strtotime('-1 month', $nowEndTime);
                    $prevEndTime = strtotime('-1 month', $nowStartTime);
                    $prevList = $this->queryData($prevStartTime, $prevEndTime, '%H:00', $map, 0, 0);
                    $arr = $this->hours;
                    foreach ($arr as $key => $value) {
                        foreach ($prevList as $k => $v) {
                            if ($value['section'] == $v['section']) {
                                $arr[$key]['total'] = $v['total'];
                            }
                        }
                    }
                    $farLine = array_column($arr, 'total');
                    $title[1] = '上个月这天';
                }
                //性别分析
                $genderList = $this->queryGenderData($nowStartTime, $nowEndTime, $map);
                break;
            case '7day':
                //近7天
                $nowEndTime = strtotime($this->today_date . ' 23:59:59');
                $date = $this->_getDate('-6 day', $this->today_date);
                $nowStartTime = strtotime($date);
                $nearList = $this->queryData($nowStartTime, $nowEndTime, '%m/%d', $map, 6);
                $abscissa = array_column($nearList, 'section');
                $nearLine = array_column($nearList, 'total');
                $title[0] = '近7天';
                if ($contrast == 'hb') { //环比
                    //上7天
                    $prevEndTime = $nowStartTime - 1;
                    $prevStartTime = strtotime($this->_getDate('-6 day', date('Y-m-d', $prevEndTime)));
                    $farList = $this->queryData($prevStartTime, $prevEndTime, '%m/%d', $map, 6);
                    $farLine = array_column($farList, 'total');
                    $title[1] = '上7天';
                } else { //同比
                    //上个月这7天
                    $prevEndTime = strtotime('-1 month', $nowEndTime);
                    $prevStartTime = strtotime('-6 day', $prevEndTime);
                    $farList = $this->queryData($prevStartTime, $prevEndTime, '%m/%d', $map, 6);
                    $farLine = array_column($farList, 'total');
                    $title[1] = '上个月这7天';
                }
                //7天流量分析
                $list = $nearList;
                //性别分析
                $genderList = $this->queryGenderData($nowStartTime, $nowEndTime, $map);
                //每天小时数量
                $hourList = $this->getEverydayRatio($nowStartTime, $nowEndTime, $map);
                break;
            case '30day':
                //近30天
                $nowEndTime = strtotime($this->today_date . ' 23:59:59');
                $date = $this->_getDate('-29 day', $this->today_date);
                $nowStartTime = strtotime($date);
                $nearList = $this->queryData($nowStartTime, $nowEndTime, '%m/%d', $map, 29);
                $nearArr = $this->_dispose($nearList, 5);
                $abscissa = array_column($nearArr, 'section');
                $nearLine = array_column($nearArr, 'total');
                $title[0] = '近30天';
                if ($contrast == 'hb') { //环比
                    //上30天
                    $prevEndTime = $nowStartTime - 1;
                    $prevStartTime = strtotime($this->_getDate('-29 day', date('Y-m-d', $prevEndTime)));
                    $farList = $this->queryData($prevStartTime, $prevEndTime, '%m/%d', $map, 29);
                    $farArr = $this->_dispose($farList, 5);
                    $farLine = array_column($farArr, 'total');
                    $title[1] = '上30天';
                } else { //同比
                    //上个月这30天
                    $prevEndTime = strtotime('-1 month', $nowEndTime);
                    $prevStartTime = strtotime('-29 day', $prevEndTime);
                    $farList = $this->queryData($prevStartTime, $prevEndTime, '%m/%d', $map, 29);
                    $farArr = $this->_dispose($farList, 5);
                    $farLine = array_column($farArr, 'total');
                    $title[1] = '上个月这30天';
                }
                //30天流量分析
                $list = $nearArr;
                //性别分析
                $genderList = $this->queryGenderData($nowStartTime, $nowEndTime, $map);
                //每天小时数量
                $hourList = $this->getEverydayRatio($nowStartTime, $nowEndTime, $map);
                break;
            case '90day':
                //近90天
                $nowEndTime = strtotime($this->today_date . ' 23:59:59');
                $date = $this->_getDate('-89 day', $this->today_date);
                $nowStartTime = strtotime($date);
                $nearList = $this->queryData($nowStartTime, $nowEndTime, '%Y/%m/%d', $map, 89);
                $nearArr = $this->_dispose($nearList, 10);
                $abscissa = array_column($nearArr, 'section');
                $nearLine = array_column($nearArr, 'total');
                $title[0] = '近90天';
                if ($contrast == 'hb') {  //环比
                    //上90天
                    $prevEndTime = $nowStartTime - 1;
                    $prevStartTime = strtotime($this->_getDate('-89 day', date('Y-m-d', $prevEndTime)));
                    $farList = $this->queryData($prevStartTime, $prevEndTime, '%Y/%m/%d', $map, 29);
                    $farArr = $this->_dispose($farList, 10);
                    $farLine = array_column($farArr, 'total');
                    $title[1] = '上90天';
                } else {
                    //去年这90天
                    $prevEndTime = strtotime('-1 year', $nowEndTime);
                    $prevStartTime = strtotime('-89 day', $prevEndTime);
                    $farList = $this->queryData($prevStartTime, $prevEndTime, '%Y/%m/%d', $map, 29);
                    $farArr = $this->_dispose($farList, 10);
                    $farLine = array_column($farArr, 'total');
                    $title[1] = '去年这90天';
                }
                //90天流量分析
                $list = $nearArr;
                //性别分析
                $genderList = $this->queryGenderData($nowStartTime, $nowEndTime, $map);
                //每天小时数量
                $hourList = $this->getEverydayRatio($nowStartTime, $nowEndTime, $map);
                break;
            default:
                $abscissa = $nearLine = $farLine = $list = $genderList = [];
        }
        $data = [
            'title' => $title,
            'abscissa' => $abscissa,
            'near_line' => $nearLine,
            'far_line' => $farLine,
            'list' => $list,
            'gender_list' => $genderList,
            'hourList' => $hourList ?? [],
            'page_info' => []
        ];
        return returnJson(HTTP_CODE_SUCCESS, '成功', $data);
    }

    /**
     * 获取全门店人流量
     * @param $datas
     * @param $contrast
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getAllShopFlow($datas, $contrast)
    {
        $title = [];
        $page = $datas['page'] ?? 1;
        $dimension = $datas['dimension'];
        switch ($dimension) {
            case 'today':
                //今天
                $nowEndTime = strtotime($this->today_date . ' 23:59:59');
                $nowStartTime = strtotime($this->today_date . ' 00:00:00');
                $title[0] = '今天';
                if ($contrast == 'hb') { //环比
                    //昨天
                    $prevEndTime = $nowStartTime - 1;
                    $prevStartTime = strtotime($this->_getDate('-0 day', date('Y-m-d', $prevEndTime)));
                    $title[1] = '昨天';
                } else {
                    //上个月这天
                    $prevEndTime = strtotime('-1 month', $nowEndTime);
                    $prevStartTime = strtotime('-0 day', $prevEndTime);
                    $title[1] = '上个月这天';
                }
                break;
            case 'yesterday':
                //昨天
                $nowEndTime = strtotime('-1 day', strtotime($this->today_date . ' 23:59:59'));
                $nowStartTime = strtotime('-1 day', strtotime($this->today_date . ' 00:00:00'));
                $title[0] = '昨天';
                if ($contrast == 'hb') { //环比
                    //前天
                    $prevEndTime = $nowStartTime - 1;
                    $prevStartTime = strtotime($this->_getDate('-0 day', date('Y-m-d', $prevEndTime)));
                    $title[1] = '前天';
                } else {
                    //上个月这天
                    $prevEndTime = strtotime('-1 month', $nowEndTime);
                    $prevStartTime = strtotime('-0 day', $prevEndTime);
                    $title[1] = '上个月这天';
                }
                break;
            case '7day':
                //近7天
                $nowEndTime = strtotime($this->today_date . ' 23:59:59');
                $date = $this->_getDate('-6 day', $this->today_date);
                $nowStartTime = strtotime($date);
                $title[0] = '近7天';
                if ($contrast == 'hb') { //环比
                    //上7天
                    $prevEndTime = $nowStartTime - 1;
                    $prevStartTime = strtotime($this->_getDate('-6 day', date('Y-m-d', $prevEndTime)));
                    $title[1] = '上7天';
                } else {
                    //去年这7天
                    $prevEndTime = strtotime('-1 year', $nowEndTime);
                    $prevStartTime = strtotime('-6 day', $prevEndTime);
                    $title[1] = '去年这7天';
                }
                break;
            case '30day':
                //近30天
                $nowEndTime = strtotime($this->today_date . ' 23:59:59');
                $date = $this->_getDate('-29 day', $this->today_date);
                $nowStartTime = strtotime($date);
                $title[0] = '近30天';
                if ($contrast == 'hb') { //环比
                    //上30天
                    $prevEndTime = $nowStartTime - 1;
                    $prevStartTime = strtotime($this->_getDate('-29 day', date('Y-m-d', $prevEndTime)));
                    $title[1] = '上30天';
                } else {
                    //去年这30天
                    $prevEndTime = strtotime('-1 year', $nowEndTime);
                    $prevStartTime = strtotime('-29 day', $prevEndTime);
                    $title[1] = '去年这30天';
                }
                break;
            case '90day':
                //近90天
                $nowEndTime = strtotime($this->today_date . ' 23:59:59');
                $date = $this->_getDate('-89 day', $this->today_date);
                $nowStartTime = strtotime($date);
                $title[0] = '近90天';
                if ($contrast == 'hb') { //环比
                    //上90天
                    $prevEndTime = $nowStartTime - 1;
                    $prevStartTime = strtotime($this->_getDate('-89 day', date('Y-m-d', $prevEndTime)));
                    $title[1] = '上90天';
                } else {
                    //上年这90天
                    $prevEndTime = strtotime('-1 year', $nowEndTime);
                    $prevStartTime = strtotime('-89 day', $prevEndTime);
                    $title[1] = '上年这90天';
                }
                break;
            default:
                return [];
                break;
        }
        $data = $this->queryShopData($nowStartTime, $nowEndTime, $page);
        $list = $data['list'];
        $abscissa = array_column($list, 'section');
        $nearLine = array_column($list, 'total');
        $pageInfo = [
            'total' => $data['total'],
            'currentPage' => $data['currentPage'],
            'lastPage' => $data['lastPage']
        ];
        if ($contrast == 'hb') { //环比
            $farData = $this->queryShopData($prevStartTime, $prevEndTime, $page);
            $farList = $farData['list'];
            //没有的补0
            if (count($list) != count($farList)) {
                $farLine = [];
                foreach ($list as $key => $value) {
                    $farLine[] = 0;
                    foreach ($farList as $k => $vo) {
                        if ($value['shop_id'] == $vo['shop_id']) {
                            $farLine[] = $value['total'];
                        }
                    }
                }
            } else {
                $farLine = array_column($farList, 'total');
            }
        } else { //同比
            $farData = $this->queryShopData($prevStartTime, $prevEndTime, $page);
            $farList = $farData['list'];
            //没有的补0
            if (count($list) != count($farList)) {
                $farLine = [];
                foreach ($list as $key => $value) {
                    $farLine[] = 0;
                    foreach ($farList as $k => $vo) {
                        if ($value['shop_id'] == $vo['shop_id']) {
                            $farLine[] = $value['total'];
                        }
                    }
                }
            } else {
                $farLine = array_column($farList, 'total');
            }
        }
        $genderList = $this->queryGenderData($nowStartTime, $nowEndTime, []);
        return [
            'title' => $title,
            'abscissa' => $abscissa,
            'near_line' => $nearLine,
            'far_line' => $farLine,
            'list' => $list,
            'gender_list' => $genderList,
            'page_info' => $pageInfo
        ];
    }

    /**
     * 查询数据
     * @param $startTime | 开始时间
     * @param $endTime | 结束时间
     * @param $op | 时间操作符 ge: %Y-%m-%d
     * @param $map | 查询条件
     * @param int $type | 区分时间还是天的类型
     * @param $num | 循环数量
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function queryData($startTime, $endTime, $op, $map, $num, $type = 1)
    {
        $list = $this->app->db->name($this->table)
            ->whereBetween('enter_time', $startTime . ',' . $endTime)
            ->field('count(id) AS total,FROM_UNIXTIME(enter_time, "' . $op . '") AS section')
            ->where('is_del', 1)
            ->where($map)
            ->group('section')
            ->select()->toArray();
        if ($type && count($list) != $num + 1) {
            if ($num == 6 || $num == 29) {
                $op = 'm/d';
            } else {
                $op = 'Y/m/d';
            }
            $start = date($op, $startTime);
            $dateTime = [];
            for ($i = 0; $i <= $num; $i++) {
                if ($i == 0) {
                    $dateTime[] = $start;
                } else {
                    $dateTime[] = date($op, strtotime("+{$i} day", strtotime($start)));
                }
            }
            $now = [];
            foreach ($dateTime as $key => $vo) {
                $now[$key]['total'] = 0;
                $now[$key]['section'] = $vo;
                foreach ($list as $k => $v) {
                    if ($vo == $v['section']) {
                        $now[$key]['total'] = $v['total'];
                    }
                }
            }
            $list = $now;
        }
        return $list;
    }

    /**
     * 获取时间
     * @param $op
     * @param $time
     * @return false|string
     */
    protected function _getDate($op, $time)
    {
        return date('Y-m-d', strtotime($op, strtotime($time)));
    }

    /**
     * 查询性别数据
     * @param $startTime
     * @param $endTime
     * @param $map
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function queryGenderData($startTime, $endTime, $map)
    {
        $list = $this->app->db->name($this->table)
            ->where('enter_time', '>=', $startTime)
            ->where('enter_time', '<=', $endTime)
            ->where($map)
            ->group('sex')
            ->field('sex,count(id) AS total')//1男 2女
            ->select()->toArray();
        return $list;
    }

    /**
     * 处理数据
     * @param $list
     * @param $len | 截取长度
     * @return array
     */
    protected function _dispose($list, $len)
    {
        if ($len == 5) {
            $period = $this->period;
        } else {
            $period = $this->month_period;
        }
        $arr = [];
        foreach ($period as $key => $value) {
            $arr[$key]['total'] = 0;
            $arr[$key]['section'] = '';
            foreach ($list as $k => $vo) {
                if (in_array($k, $value)) {
                    $arr[$key]['total'] += $vo['total'];
                    $arr[$key]['section'] .= $vo['section'];
                }
            }
        }
        foreach ($arr as $key => $value) {
            $arr[$key]['section'] = substr($value['section'], 0, $len) . '-' . substr($value['section'], -$len, $len);
        }
        return $arr;
    }

    /**
     * 分页获取门店数据
     * @param $startTime
     * @param $endTime
     * @param $page
     * @return array
     * @throws \think\db\exception\DbException
     */
    public function queryShopData($startTime, $endTime, $page)
    {
        $obj = $this->app->db->name('lg_distributor')
            ->where('status', 1)
            ->field('id AS shop_id,name AS section')
            ->paginate(20, false, ['page' => $page]);
        $list = $obj->items();
        $shopIds = array_column($list, 'shop_id');
        $faceList = $this->app->db->name($this->table)
            ->whereIn('shop_id', $shopIds)
            ->whereBetween('enter_time', $startTime . ',' . $endTime)
            ->group('shop_id')
            ->column('count(id) AS total', 'shop_id');
        foreach ($list as $key => $value) {
            $list[$key]['total'] = $faceList[$value['shop_id']] ?? 0;
        }
        return [
            'list' => $list,
            'total' => $obj->total(),
            'currentPage' => $obj->currentPage(),
            'lastPage' => $obj->lastPage()
        ];
    }

    /**
     * 获取每天的每个小时的数量
     * @param $startTime
     * @param $endTime
     * @param $map
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getEverydayRatio($startTime, $endTime, $map)
    {
        $faceList = $this->app->db->name($this->table)
            ->whereBetween('enter_time', $startTime . ',' . $endTime)
            ->field('count(id) AS total,FROM_UNIXTIME(enter_time, "%H:00") AS section')
            ->where($map)
            ->group('section')
            ->select()->toArray();
        $list = $this->hours;
        foreach ($list as $key => $value) {
            foreach ($faceList as $k => $v) {
                if ($value['section'] == $v['section']) {
                    $list[$key]['total'] = $v['total'];
                }
            }
        }
        return $list;
    }
}